﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="YoProgramo.Infrastructure.Tools.PagedList"%>
<%@ Import Namespace="YoProgramo.Domain.Core.Entities"%>
<%@ Import Namespace="YoProgramo.Domain.BusinessLogic.Service"%>
<%@ Import Namespace="YoProgramo.Domain.Core.Interfaces"%>
<%@ Import Namespace="YoProgramo.BusinessLogic.Service"%>
<%@ Import Namespace="Microsoft.Practices.ServiceLocation"%>

    <%
      var SpamService = ServiceLocator.Current.GetInstance<IMarkAsSpamService<Comment>>();
      var s = (IPagedList<IComment>)ViewData.Model;                       
    %>
       
    <table cellpadding=15 width="690px" class="TableAdmin">
      <tr class="TableAdminHead">
        <td>
          Id
        </td>
        <td>
          Comentario
        </td>    
        <td>
          Pregunta
        </td>    
        <td>
          Usuario
        </td>
        <td>
          Fecha
        </td>                 
        <td>
          Spams
        </td>        
        <td>
          Acciones
        </td>        
      </tr>
    <%foreach (IComment comment in s)
    {
    %>    
      <tr class="rowsimple">
        <td>
          <%=comment.Id %>
        </td>
        <td>
          <%=comment.TextBody.Substring(0, comment.TextBody.Length > 50 ? 50 : comment.TextBody.Length) + "..."%>
        </td>
        <td>
          <%=comment.ForStory.Title %> <%if ((bool)ViewData["ShowStoryFilterLink"]) {%> (<%=Html.RouteLink("Filtrar", "AdminByStory", new {controller = "Admin", action = "CommentList", bystory = comment.ForStory.Id })%>)<%}%>
        </td>         
        <td>
          <%=comment.ByUser.UserName %> <%if ((bool)ViewData["ShowUserFilterLink"]){%> (<%=Html.RouteLink("Filtrar", "AdminByUser", new {controller = "Admin", action = "CommentList", byuser = comment.ByUser.Id})%>)<%}%>
        </td>
        <td>
          <%=comment.CommentedAt.ToShortDateString() %>
        </td>        
        <td>
          <%= SpamService.GetAllBy((Comment) comment).Count  %><span>(<%= SpamService.GetAllAprovedBy((Comment) comment).Count %>)</span> Ver
        </td>                        
        <td>               
          <%=Html.RouteLink("Editar", "Admin", new { controller = "Admin", action = "EditComment", id = comment.Id })%><br />
          <% using (Html.BeginRouteForm("Admin", new { action = "DeleteComment", id = ((Comment)comment).Id }, FormMethod.Post, new { id = "form-del-" + ((Comment)comment).Id.ToString() }))  
          { %>  
           <a href="javascript:" onclick="javascript: $('#form-del-<%= ((Comment)comment).Id %>').submit();">Borrar</a>  
          <% } %>
        </td>
      </tr>      
      <%
    }%>  
    </table>       
           
    <%= Html.Paging<IComment>(s, ViewData["UrlPaging"] as string, "__PAGENUM__")%>

